package yiminsu.com.cn.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import yiminsu.com.cn.service.HomeStayService;
import yiminsu.com.cn.utils.FileUtils;

@RestController
@RequestMapping("/Homestay")
public class HomestayController {

	@Autowired
	private HomeStayService homeStayService;

	//添加民宿
	@RequestMapping("/Addhomestay.do")
	@ResponseBody
	public Object Addhomestay(Integer hotetype,String companyname,String hotelTitle,String trafficGuide,String provincial,String city
			,String county,String hotephone,Integer type,@RequestParam(value="files",required=false)MultipartFile[] files
			,String hotelVideo,String hotelSynopsis,String hotelIntroduce,String legalperson,String legalpersonphone,
			String legalpersonemail,Double commission,@RequestParam(value="sfzs",required=false)MultipartFile[] sfzs,
			@RequestParam(value="cense",required=false)MultipartFile cense,@RequestParam(value="company",required=false)MultipartFile company
			,Integer isconsent,Double longitude,Double latitude,String registerPhoneNum,Integer userid,String remarks){

		Integer status=null;
		Map<String,Object> map=new HashMap<String, Object>();
		//处理主表图片
		StringBuffer hotelImage=new StringBuffer();//主表图片地址
		List<String> listimage= FileUtils.Fileupload(files);//中间表list
		for (int i = 0; i < listimage.size(); i++) {
			hotelImage.append(listimage.get(i)+"##");
		}
		//身份证图片处理
		List<String> sfzimage= FileUtils.Fileupload(sfzs);//身份证图片


		//处理民宿营业执照图片
		String hotelicense=FileUtils.Fileuploads(cense);
		//处理公司营业执照
		String companylicense="";
		if(hotetype==1){//有公司营业执照
			companylicense=FileUtils.Fileuploads(company);
		}
		status=homeStayService.Addhomestay(hotetype, companyname, hotelTitle,
				trafficGuide, provincial, city, county, hotephone, type, listimage,
				hotelImage.toString(), hotelVideo, hotelSynopsis, hotelIntroduce,
				legalperson, legalpersonphone, legalpersonemail, commission, 
				sfzimage, hotelicense, companylicense,isconsent,longitude,latitude,registerPhoneNum,userid,remarks);
		map.put("status", status);
		return map;
	}
	//删除民宿
	@RequestMapping("/deletehomestay.do")
	@ResponseBody
	public Object DeleteHomestay(Integer hotelId){
		return homeStayService.DeleteHomestay(hotelId);
	}
	
}
